//一般直接写在一个js文件中
layui.use(['element', 'form', 'layer'], function () {
    $ = layui.$;
    var form = layui.form,
        layer = layui.layer;



    //密码验证
    form.verify({
        password: function (value) { //value：表单的值、item：表单的DOM对象
            if (value === "" || value == null || value.length < 6 || value.length > 16) {
                return '密码必须是6-16位';
            } else {
                var pswd = /^[0-9a-zA-Z_$!?]{6,16}$/;
                if (!pswd.test(value)) {
                    return "您输入的密码不符合规则，请从新输入"
                }
            }
        }
    });

    form.on('submit(submitBtn)', function (data) {
        var phone = data.field.phone;
        var id = data.field.id;
        var flag = false;

        $.ajax({
            url: "/user/exists",
            type: "get",
            dataType: "json",
            data: {phone: phone, id: id},
            async: false,
            success: function (rs) {
                if (rs.code != 200) {
                    layer.msg(rs.message, {icon: 2});
                } else {
                    flag = true;
                }
            }
        });
        return flag; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
    });


});